
package com.cx.bank.factory;

import java.io.IOException;
import java.util.ResourceBundle;
import com.cx.bank.dao.BankDaoInterface;

/**
  * 工厂模式
 * @author 华s
 */
public class UserDaoFactory {
	private static UserDaoFactory instance;

	public BankDaoInterface userdao;

	private UserDaoFactory() throws IOException, ClassNotFoundException, InstantiationException {
		// 从文件中读取所需的持久层对象
		ResourceBundle bundle = ResourceBundle.getBundle("className");

		// 通过反射创建对象
		String className = bundle.getString("className");
		// String className = props.getProperty("className");
		// String className ="com.cx.bank.dao.FileDao"; //硬编码

		Class<?> c = Class.forName(className);
		Object o;

		try {
			o = c.newInstance();
			userdao = (BankDaoInterface) o;
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}

	}

	public static synchronized UserDaoFactory getInstance()
			throws IOException, ClassNotFoundException, InstantiationException {
		if (instance == null) {
			instance = new UserDaoFactory();
		}
		return instance;
	}

	
	public BankDaoInterface createFactoryDao() {
		return userdao;
	}

}
